/**
 * Copyright phonemap.com
 *
 * Licensed under the phonemap.com License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.phonemap.com/licenses/LICENSE-1.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * Init login facebook.
 */
window.fbAsyncInit = function() {
	FB.init({
		appId      : '1435764669997973',//phonemaptest1435764669997973
//		appId : '157906274356332', //phonemap 				    			
		status : true, // check login status
		cookie : true, // enable cookies to allow the server to access the session
		xfbml : true
	});

	FB.Event.subscribe('auth.authResponseChange', function(response) {
		if (response.status === 'connected') {
			afterLogin();
		} else if (response.status === 'not_authorized') {
			FB.login();
		} else {
			FB.login();
		}
	});
};

// Load the SDK asynchronously
(function(d) {
	var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
	if (d.getElementById(id)) {
		return;
	}
	js = d.createElement('script');
	js.id = id;
	js.async = true;
	js.src = "//connect.facebook.net/de_DE/all.js";
	ref.parentNode.insertBefore(js, ref);
}(document));

/**
 * After login.
 */
function afterLogin() {
	//Step 01: check to insert user.
	insertFacebookUser();
}